import UIKit

/**
    B站：https://www.bilibili.com/video/BV144411C7Gg?p=22

    第22课
        1. 结构体
        2. matating 关键字
        3. 结构体实例也是值传递
        4. 常亮和变量实例 (不可更改)
 */



// 1. 结构体
struct Student {
    var name = "unknow"
    var age = 0
    var score = 0.0
    var isPass = false
    
    static let schoolName = "家里蹲大学" // 4. 常亮和变量实例
    let preClassName = "班级" // 4. 常亮和变量实例
    
    init() {

    }
    
    init(name: String, age: Int, score: Double) {
        self.name = name
        self.age = age
        self.score = score
        
        if (score < 60) {
            self.isPass = false
        } else {
            self.isPass = true
        }
    }
    
    
    // 不建议写这个, 因为和 属性 getter/setter 一样功能的
//    func getName() -> String {
//        return self.name
//    }
//    mutating func setName(value: String) -> Void {
//        self.name = value
//    }
    
    // 仅 定义一个方法名，用到了 self
    mutating func setScore(value: Double) -> Void {
        self.score = value
        if value < 60.0 {
            self.isPass = false
        } else {
            self.isPass = true
        }
    }
}

var xm = Student()
print("xm init =>\(xm)")
xm.name = "srxboys"
xm.age = 10
xm.score = 90.5 // isPass: false -> this is bug ----------------------------
print("xm ..  =>\(xm)")
xm.setScore(value: 80.0) // isPass: true
print("xm ..  =>\(xm)")
print("学校 = " + Student.schoolName)

var xiaoming = Student.init(name: "小明", age: 18, score: 61.5)
print(xiaoming)
print("xiaoming isPass=", xiaoming.isPass)
xiaoming.age = 20
print("xiaoming age=", xiaoming.age)
print(xiaoming)


// 2. matating 关键字
// func 内部使用 self


// 3. 结构体实例也是值传递
xm.age = 10
xiaoming.age = 20

// 4. 常亮和变量实例
